package com.zsrt.javaweb;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserNameFilter extends  HttpFilter {

	@Override
	public void doHttpFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		System.out.println("进入UserNameFilter...");
		String username = request.getParameter("username");
		String webUsername = getFilterConfig().getInitParameter("username");
		if(!username.equals(webUsername)){
			//放置错误提示消息
			request.setAttribute("message", "用户名错误...");
			
			//如果username不等于"scott"就将请求转发到login.jsp
			request.getRequestDispatcher("/login.jsp").forward(request, response);
			
			//表示不执行后面的方法 不交给下一个过滤器处理
			return;
		}
		chain.doFilter(request, response);
		
	}
	

	

}
